#include <glib.h>

static void _queue_foreach_func(gpointer data, gpointer       user_data)
{
    g_print("user_data:%s, data:%d \n", (gchar *)user_data, GPOINTER_TO_INT(data));
}

gint main(gint argc, gchar **argv)
{
    GQueue *q = NULL;
    GList *l1 = NULL, *l2 = NULL;
    gboolean removed = FALSE;
    guint num = 0;

    q = g_queue_new();

    g_queue_push_tail(q, GINT_TO_POINTER(10));
    g_queue_push_tail(q, GINT_TO_POINTER(15));
    g_queue_push_tail(q, GINT_TO_POINTER(20));
    g_queue_push_tail(q, GINT_TO_POINTER(25));
    g_queue_push_tail(q, GINT_TO_POINTER(30));
    g_queue_push_tail(q, GINT_TO_POINTER(20));
    // result: 10-15-20-25-30-20

    g_queue_foreach(q, _queue_foreach_func, "Queue-push");

    // remove
    removed = g_queue_remove(q, GINT_TO_POINTER(30));
    num = g_queue_remove_all(q, GINT_TO_POINTER(20));
    g_print("removed-30:%s, num-20:%d \n", removed? "TRUE":"FALSE", num);
    // result: 10-15-25

    g_queue_foreach(q, _queue_foreach_func, "Queue-after-remove");

    // find GList and unlink
    l1 = g_queue_find(q, GINT_TO_POINTER(15));
    g_queue_unlink(q, l1);
    g_queue_foreach(q, _queue_foreach_func, "Queue-after-unlink");
    // result: 10-25

    // find GList and delete
    l2 = g_queue_find(q, GINT_TO_POINTER(25));
    g_queue_delete_link(q, l2);
    g_queue_foreach(q, _queue_foreach_func, "Queue-after-delete");
    // result: 10

    g_list_free(l1);
    g_queue_free(q);

    return 0;
}